package demo3;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

class Employee {
    String department;
    double salary;

    public Employee(String department, double salary) {
        this.department = department;
        this.salary = salary;
    }
}

public class MapGroupingAndStatistics {
    public static void main(String[] args) {
        List<Employee> employees = new ArrayList<>();
        employees.add(new Employee("HR", 5000));
        employees.add(new Employee("IT", 6000));
        employees.add(new Employee("HR", 4500));
        Map<String, Double> departmentTotalSalaries = new HashMap<>();
        for (Employee employee : employees) {
            departmentTotalSalaries.merge(employee.department, employee.salary, Double::sum);
        }
        System.out.println("各部门总工资: " + departmentTotalSalaries);
    }
}
